﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace Atomic.Permission.Entities
{
    /// <summary>
    /// 用户窗体
    /// </summary>
    public class FormEntity
    {
        /// <summary>
        /// 排序字段
        /// </summary>
        public const string SORT = "Sort";

        public FormEntity()
        {
            Cls = string.Empty;
            Url = string.Empty;
        }

        #region 基本属性

        /// <summary>
        /// 自增主键
        /// </summary>
        public virtual int ID { set; get; }
        /// <summary>
        /// 窗体名称
        /// </summary>
        [DisplayName("功能名")]
        [Required]
        [StringLength(20)]
        public virtual string Name { set; get; }
        /// <summary>
        /// 父级窗体
        /// </summary>
        public virtual int PID { set; get; }
        /// <summary>
        /// 窗体路径
        /// </summary>
        [DisplayName("地址/路径")]
        [StringLength(255)]
        public virtual string Url
        {
            set
            {
                _url = value;
            }
            get
            {
                return _url == null ? string.Empty : _url;
            }
        }
        private string _url;

        /// <summary>
        /// 排列顺序
        /// </summary>
        [DisplayName("顺序")]
        [Required]
        [Range(0, 99999)]
        public virtual int Sort { set; get; }

        /// <summary>
        /// 样式
        /// </summary>
        [DisplayName("自定义样式")]
        [StringLength(255)]
        public virtual string Cls
        {
            set
            {
                _cls = value;
            }
            get
            {
                return _cls == null ? string.Empty : _cls;
            }
        }
        private string _cls;

        /// <summary>
        /// 唯一键
        /// </summary>
        [DisplayName("键值")]
        [Required]
        [StringLength(255)]
        public virtual string Key { set; get; }

        /// <summary>
        /// 相关联子窗体数量
        /// </summary>
        public virtual int ChildrenCount
        {
            set
            {
                _childrenCount = value;
                this.state = value > 0 ? "closed" : "open";
            }
            get
            {
                return _childrenCount;
            }
        }
        private int _childrenCount;

        /// <summary>
        /// 是否启用
        /// </summary>
        [DisplayName("是否启用")]
        public virtual bool Enabled { set; get; }

        #endregion

        #region 扩展属性

        //TreeGrid使用的属性
        public virtual string state { set; get; }

        /// <summary>
        /// 拥有的功能点
        /// </summary>
        public virtual List<FunPointEntity> FunPoints { set; get; }
        #endregion
    }
}
